package de.baumann.browser.activitys.hash

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.TextView
import com.umeng.socialize.UMShareAPI
import de.baumann.browser.R
import de.baumann.browser.activitys.AbstractShareActivity
import de.baumann.browser.activitys.center.CreatePoolActivity
import de.baumann.browser.adapter.InviteRankingAdapter
import de.baumann.browser.api.net.vo.InviteInfo
import de.baumann.browser.iview.InviteView
import de.baumann.browser.present.InvitePresenter
import de.baumann.browser.views.dialog.HashAchieveDialog
import kotlinx.android.synthetic.main.activity_invite.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 * @author：
 * @date：2018/10/24
 * @discription: 邀请好友
 */
class InviteActivity : AbstractShareActivity<InviteView, InvitePresenter>(), InviteView {

    private var inviteRankingAdapter: InviteRankingAdapter? = null

    private var withdrawed: String? = null

    override fun getLayout(): Int {
        return R.layout.activity_invite
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        findViewById<View>(R.id.btnInvite).setOnClickListener(this)

        inviteRankingAdapter = InviteRankingAdapter(R.layout.recycler_item_invite_ranking)
        rvInviteList.adapter = inviteRankingAdapter
    }

    override fun initData() {
        presenter.getSpreadInfos()
    }

    override fun createPresenter(): InvitePresenter? {
        return InvitePresenter()
    }

    override fun createView(): InviteView? {
        return this
    }

    override fun onClick(view: View) {
        if (R.id.btnInvite == view.id) {
            displaySharePanel()
        } else {
            super.onClick(view)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
//        super.onActivityResult(requestCode, resultCode, data)
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data)
    }

    override fun setInviteList(datas: List<InviteInfo.ListEntity>?) {
        inviteRankingAdapter!!.setNewData(datas)
    }

    override fun setContribute(contribute: String) {
        (findViewById<View>(R.id.tvContribute) as TextView).text = contribute
    }

    override fun setAccountBalance(balance: Double) {}

    @SuppressLint("SetTextI18n")
    override fun setInviteCount(count: Int) {
        tvAllInvate.text = count.toString()
    }

    override fun setTotalIncome(totalIncome: String) {}

    override fun setLevel(progress: Int) {
        when (progress) {
            1 -> {
            }
            2 -> {
            }
            3 -> {
            }
        }
    }

    override fun setWithdrawed(withdrawed: String) {
        this.withdrawed = withdrawed
    }

    override fun canCreatePool() {
        HashAchieveDialog(mContext, View.OnClickListener { CreatePoolActivity.startCreatePoolActivity(mContext) }).show()
    }

    companion object {

        fun startInviteActivity(context: Context) {
            context.startActivity(Intent(context, InviteActivity::class.java))
        }
    }
}
